package com.ly.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPoolDemo {

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        ExecutorService executorService1 = Executors.newSingleThreadExecutor();
        ExecutorService executorService2 = Executors.newCachedThreadPool();
//         try{
//            for(int i=0;i<10;i++) {
//                executorService.execute( () -> {
//                    System.out.println(Thread.currentThread().getName());
//                });
//            }
//        }catch(Exception e){
//
//        }finally {
//            executorService.shutdown();
//        }
//        try{
//            for(int i=0;i<10;i++) {
//                executorService1.execute( () -> {
//                    System.out.println(Thread.currentThread().getName());
//                });
//            }
//        }catch(Exception e){
//
//        }finally {
//            executorService1.shutdown();
//        }

        try{
            for(int i=0;i<10;i++) {
                executorService2.execute( () -> {
                    System.out.println(Thread.currentThread().getName());
                });
            }
        }catch(Exception e){

        }finally {
            executorService2.shutdown();
        }

    }
}
